package com.marketing.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务发现调试控制器
 * 用于查看注册的服务实例
 */
@RestController
public class DiscoveryController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/discovery/services")
    public Map<String, Object> getServices() {
        Map<String, Object> result = new HashMap<>();
        
        // 获取所有服务名
        List<String> services = discoveryClient.getServices();
        result.put("services", services);
        
        // 获取auth-service的所有实例
        List<ServiceInstance> authInstances = discoveryClient.getInstances("auth-service");
        result.put("authServiceInstances", authInstances);
        
        return result;
    }
}